//
//  LWMainViewController.swift
//  MicroBlog
//
//  Created by 孙程 on 2017/7/13.
//  Copyright © 2017年 孙程. All rights reserved.
//

import UIKit

class LWMainViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
        //设置tintColor
        UITabBar.appearance().tintColor = UIColor.orange
        
        //使用KVC 给oc中的类设置只读属性
        let lwTabBar = LWTabBar()
        
        lwTabBar.composeBtnClouser = {[weak self]in
            print("闭包调用")
        }
        setValue(lwTabBar, forKey: "tabBar")

       //添加自视图控制器
        addChildViewController(childController: LWHomeTableViewController(), title: "首页", imageName: "tabbar_home")
        addChildViewController(childController: LWMessageTableViewController(), title: "消息", imageName: "tabbar_message_center")
        addChildViewController(childController: LWDiscoverTableViewController(), title: "发现", imageName: "tabbar_discover")
        addChildViewController(childController: LWMineTableViewController(), title: "我的", imageName: "tabbar_profile")
        
    }
    //添加子视图控制器的方法重载
    func addChildViewController(childController:UIViewController,title:String,imageName:String){
        
        //设置tabbar的文字和图片
        childController.tabBarItem.image = UIImage(named: imageName)
        childController.tabBarItem.selectedImage = UIImage(named: "\(imageName)_selected")
        //childController.tabBarItem.title = title
        //childController.navigationItem.title = title
        //标题
        childController.title = title
        
        //创建导航视图控制器
        let nav = LWNavigationController(rootViewController: childController)
        
        // 添加子视图
        addChildViewController(nav)
        
    }
    

}
